﻿@model TianYu.CMS.Domain.DomainModel.SysMenu
@{
    ViewBag.Title = "新增/编辑";
    Layout = "~/Areas/Admin/Views/Shared/_Layout_Edit.cshtml";
}
<form class="layui-form" method="post" action="/admin/sysmenu/save" id="myForm">
    <input type="hidden" value="@Model.Id" name="Id" />
    <input type="hidden" value="@Model.ParentId" name="ParentId" />
    <input type="hidden" value="@Model.MenuIcon" name="MenuIcon" id="txtIcon" />
    <input type="hidden" value="@Model.Enabled.ToString()" name="Enabled" />
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>类型</label>
        <div class="layui-input-block">
            @*<input type="radio" name="MenuType" lay-filter="MenuType" value="1" title="系统" @(Model.MenuType < 2 ? "checked" : "")>*@
            <input type="radio" name="MenuType" lay-filter="MenuType" value="2" title="目录" @(Model.MenuType < 2 ? "checked" : "")>
            <input type="radio" name="MenuType" lay-filter="MenuType" value="3" title="菜单" @(Model.MenuType == 3 ? "checked" : "")>
            <input type="radio" name="MenuType" lay-filter="MenuType" value="4" title="按钮" @(Model.MenuType == 4 ? "checked" : "")>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>父级</label>
        <div class="layui-input-block">
            <input type="text" readonly autocomplete="off" class="layui-input" value="@ViewBag.ParentName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*</span>名称</label>
        <div class="layui-input-block">
            <input type="text" name="MenuName" required lay-verify="required" autocomplete="off" class="layui-input" maxlength="16" value="@Model.MenuName">
        </div>
    </div>
    <div class="layui-form-item dir">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input type="text" name="MenuUrl" autocomplete="off" class="layui-input" maxlength="128" value="@Model.MenuUrl">
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block" style="padding-right:0px">
                    <i class="layui-icon @(Model.MenuIcon)" id="iicon"></i>
                    <button type="button" class="layui-btn" onclick="onSelectIcon()">选择图标</button>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6">
            <div class="layui-form-item but">
                <label class="layui-form-label">JS方法</label>
                <div class="layui-input-block">
                    <input type="text" name="JsEvent" autocomplete="off" class="layui-input" maxlength="128" value="@Model.JsEvent">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item but">
        <label class="layui-form-label">按钮类型</label>
        <div class="layui-input-block">
            <input type="radio" name="IsToolbar" value="false" title="工具栏按钮" @(Model.IsToolbar == false ? "checked" : "")>
            <input type="radio" name="IsToolbar" value="true" title="自定义按钮" @(Model.IsToolbar == true ? "checked" : "")>
        </div>
    </div>
    <div class="layui-form-item but">
        <label class="layui-form-label">按钮尺寸</label>
        <div class="layui-input-block">
            <input type="radio" name="SizeStyle" value="layui-btn-xs" title="小型" @(Model.SizeStyle == "layui-btn-xs" ? "checked" : "")>
            <input type="radio" name="SizeStyle" value="layui-btn-sm" title="中型" @(Model.SizeStyle == "layui-btn-sm" || Model.SizeStyle == null ? "checked" : "")>
            <input type="radio" name="SizeStyle" value="" title="大型" @(Model.SizeStyle == "" ? "checked" : "")>
        </div>
    </div>
    <div class="layui-form-item but">
        <label class="layui-form-label">按钮颜色</label>
        <div class="layui-input-block">
            <input type="radio" name="BackColor" value="" title="蓝色" @(Model.BackColor == null ? "checked" : "")>
            <input type="radio" name="BackColor" value="layui-btn-normal" title="绿色" @(Model.BackColor == "layui-btn-normal" ? "checked" : "")>
            <input type="radio" name="BackColor" value="layui-btn-warm" title="黄色" @(Model.BackColor == "layui-btn-warm" ? "checked" : "")>
            <input type="radio" name="BackColor" value="layui-btn-danger" title="红色" @(Model.BackColor == "layui-btn-danger" ? "checked" : "")>
        </div>
    </div>
    <div class="layui-form-item but">
        <label class="layui-form-label">按钮分组</label>
        <div class="layui-input-block">
            <input type="radio" name="GroupId" value="1" title="组1" @(Model.GroupId <= 1 ? "checked" : "")>
            <input type="radio" name="GroupId" value="2" title="组2" @(Model.GroupId == 2 ? "checked" : "")>
            <input type="radio" name="GroupId" value="3" title="组3" @(Model.GroupId == 3 ? "checked" : "")>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" lay-filter="Enabled" lay-skin="switch" lay-text="启用|禁用" value="@Model.Enabled" @(Model.Enabled ? "checked" : "")>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-footer">
        <button type="button" class="layui-btn layui-btn-primary" onclick="win.close()">关闭</button>
        <button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">保存</button>
    </div>
</form>
@section Scripts{
    <script src="/adminres/Scripts/zTree/js/jquery.ztree.core-3.1.js" charset="utf-8"></script>
    <script src="/adminres/Scripts/zTree/js/jquery.ztree.excheck-3.1.js"></script>
    <script src="/adminres/Scripts/zTree/js/jquery.ztree.all-3.1.js"></script>
    <script type="text/javascript">
        $(function () {
            layui.use('form', function () {
                var form = layui.form;
                var checkVal = $('input[name=MenuType]:checked').val();
                SetShow(checkVal);
                //监听提交
                form.on('submit(formSubmit)', function (data) {
                    win.showLoading("正在保存...");
                    $("#myForm").ajaxSubmit(function (res) {
                        win.hideLoading();
                        if (res.code == 0) {
                            parent.getList();
                            parent.win.success("保存成功");
                            win.close();
                        } else {
                            win.alert(res.message);
                        }
                    });
                    return false;
                });
                form.on('switch(Enabled)', function (data) {
                    $('input[name=Enabled]').val(data.elem.checked ? 'True' : 'False');
                });
                form.on('radio(MenuType)', function (data) {
                    SetShow(data.value);
                });
            });
        });
        function SetShow(val) {
            if (val == 2) {
                $('.dir,.but').hide();
            } else if (val == 3) {
                $('.but').hide();
                $('.dir').show();
            } else {
                $('.dir,.but').show();
            }
        }
        //选择图标
        function onSelectIcon() {
            win.open("/admin/sysmenu/selecticon", 450, 400, "选择图标");
        }
    </script>
}